package com.czh.subject.domain.handler.subject;

import com.czh.subject.common.enums.SubjectTypeEnum;
import com.czh.subject.domain.convert.SubjectJudgeConverter;
import com.czh.subject.domain.entity.SubjectAnswerAndOptionBO;
import com.czh.subject.domain.entity.SubjectInfoBO;
import com.czh.subject.domain.entity.SubjectOptionBO;
import com.czh.subject.infra.basic.entity.SubjectJudge;
import com.czh.subject.infra.basic.service.SubjectJudgeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author caozaihui
 * @version 1.0
 * @description: 判断题策略
 * @since 2024/7/31 下午 2:54
 */
@Component
public class JudgeTypeHandler implements SubjectTypeHandler{
    @Resource
    private SubjectJudgeService subjectJudgeService;
    @Override
    public SubjectTypeEnum getHandlerType() {
        return SubjectTypeEnum.JUDGE;
    }

    @Override
    public boolean add(SubjectInfoBO subjectInfoBO) {
        SubjectJudge subjectJudge =new  SubjectJudge();
        subjectJudge.setSubjectId(subjectInfoBO.getId());
        subjectJudge.setIsCorrect(subjectInfoBO.getOptionList().get(0).getIsCorrect());
        return subjectJudgeService.insert(subjectJudge)>0;
    }

    @Override
    public SubjectAnswerAndOptionBO queryOptionAndAnswer(Long id) {
        SubjectJudge subjectJudge = new SubjectJudge();
        subjectJudge.setSubjectId(id);
        List<SubjectJudge> subjectJudgeList = subjectJudgeService.querySubjectJudgeList(subjectJudge);
        List<SubjectOptionBO> subjectOptionBOList = SubjectJudgeConverter.INSTANCE.convert(subjectJudgeList);
        SubjectAnswerAndOptionBO subjectAnswerAndOptionBO = new SubjectAnswerAndOptionBO();
        subjectAnswerAndOptionBO.setOptionList(subjectOptionBOList);
        return subjectAnswerAndOptionBO;
    }
}
